package interview.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * FutureTask方法获取线程返回值
 * @Author: cctv
 * @Date: 2019/5/17 11:01
 */
public class FutureTaskDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask task = new FutureTask(new MyCallable(1));
        new Thread(task).start();
        if(!task.isDone()){
            System.out.println("Task has not finished, please wait!");
        }
        // get可以阻塞知道子线程返回 也可以加个超时参数
        System.out.println("task return :"+task.get());
    }
}
